package com.example.dzcfinal;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.example.dzcfinal.SQLite.SQLite;

import java.util.List;

public class Three extends Activity {

    private LinearLayout zhan;
    private List<com.example.dzcfinal.SQLite.Goods> Goods;
    private LinearLayout one;
    private LinearLayout two;
    private LinearLayout three;
    private TextView NameOne;
    private TextView NameTwo;
    private TextView NameThree;
    private TextView give_one;
    private TextView give_two;
    private TextView give_three;
    private String NameOneText;
    private String NameTwoText;
    private String NameThreeText;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zhanlan);

        one = (LinearLayout)findViewById(R.id.one);
        two = (LinearLayout)findViewById(R.id.two);
        three = (LinearLayout)findViewById(R.id.three);
        NameOne = (TextView)findViewById(R.id.NameOne);
        NameTwo = (TextView)findViewById(R.id.NameTwo);
        NameThree = (TextView)findViewById(R.id.NameThree);
        give_one = (TextView)findViewById(R.id.give_one);
        give_two = (TextView)findViewById(R.id.give_two);
        give_three = (TextView)findViewById(R.id.give_three);
        NameOneText = NameOne.getText().toString();
        NameTwoText = NameTwo.getText().toString();
        NameThreeText = NameThree.getText().toString();
//        初始控件为不可见
        one.setVisibility(View.GONE);
        two.setVisibility(View.GONE);
        three.setVisibility(View.GONE);


//        这两个方法是判断数据库中有没有这个藏品，有的话就将Visibility改为可见
        judgeOne(NameOneText);
        judgeTwo(NameTwoText);
        judgeThree(NameThreeText);
//        设置转增按钮的点击事件，将这商品的信息删除，并且将对应控件设置为不可见
        GiveOne(NameOneText);
        GiveTwo(NameTwoText);
        GiveThree(NameThreeText);

    }

    private void GiveOne(String nameOneText) {
        give_one.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SQLite sql = new SQLite(Three.this);
                sql.deleteGood(nameOneText);
                one.setVisibility(View.GONE);
                Toast.makeText(Three.this, "转赠成功", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void GiveTwo(String nameTwoText) {
        give_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SQLite sql = new SQLite(Three.this);
                sql.deleteGood(nameTwoText);
                two.setVisibility(View.GONE);
                Toast.makeText(Three.this, "转赠成功", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private  void GiveThree(String nameThreeText) {
        give_three.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SQLite sql = new SQLite(Three.this);
                sql.deleteGood(nameThreeText);
                three.setVisibility(View.GONE);
                Toast.makeText(Three.this, "转赠成功", Toast.LENGTH_SHORT).show();
            }
        });
    }


    private void judgeOne(String Text) {
        SQLite sql = new SQLite(this);
        if (sql.findGood(Text)!=-1){
            one.setVisibility(View.VISIBLE);
        }
    }

    private void judgeTwo(String Text) {
        SQLite sql = new SQLite(this);
        if (sql.findGood(Text)!=-1){
            two.setVisibility(View.VISIBLE);
        }
    }

    private void judgeThree(String Text) {
        SQLite sql = new SQLite(this);
        if (sql.findGood(Text)!=-1){
            three.setVisibility(View.VISIBLE);
        }
    }

}
